package Sort;

public class ShellSort {
    /**
     * 希尔排序
     */

    public static void shellSort(int[] arr){
        int gap=arr.length;
        while (gap>1){
            gap/=2;
            shell(arr,gap);
        }
    }
    public static void shell(int[] arr,int gap){
        for (int i = gap; i <arr.length; i+=gap) {
            int tmp=arr[i];
            int j=i-gap;
            for (; j>=0; j-=gap) {
                if(arr[j]>tmp){
                    arr[j+gap]=arr[j];
                }else
                {
                    arr[j+gap]=tmp;
                    break;
                }
            }
            arr[j+gap]=tmp;
        }
    }
    public static void main(String[] args) {
        int[] array={9,8,7,6,5};
        shellSort(array);
        for (int i = 0; i <array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }
}
